//
//  TencentOAuth.h
//  TencentOAuthDemo
//
//  Created by cloudxu on 11-8-18.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//


#import "TencentLoginView.h"
#import "TencentRequest.h"
#import "APIBase.h"
#import "QQTLoginViewController.h"

@protocol TencentSessionDelegate;



@interface TencentOAuth : NSObject<TencentLoginViewDelegate, TencentRequestDelegate>{
	NSString* _accessToken;
	NSDate* _expirationDate;
	id<TencentSessionDelegate> _sessionDelegate;
	TencentRequest* _request;
	TencentLoginView* _loginDialog;
	NSString* _appId;
	NSString* _localAppId;
	NSString* _openId;
	NSString* _redirectURI;
	NSArray* _permissions;
	
	NSMutableDictionary*	_apiRequests;
}

@property(nonatomic, copy) NSString* accessToken;
@property(nonatomic, copy) NSDate* expirationDate;
@property(nonatomic, assign) id<TencentSessionDelegate> sessionDelegate;
@property(nonatomic, copy) NSString* localAppId;
@property(nonatomic, copy) NSString* openId;
@property(nonatomic, copy) NSString* redirectURI;

- (id)initWithAppId:(NSString *)appId
        andDelegate:(id<TencentSessionDelegate>)delegate;

- (void)authorize:(NSArray *)permissions 
		 inSafari:(BOOL)bInSafari;

- (void)authorize:(NSArray *)permissions
       localAppId:(NSString *)localAppId
		 inSafari:(BOOL)bInSafari;

- (BOOL)handleOpenURL:(NSURL *)url;

- (void)logout:(id<TencentSessionDelegate>)delegate;

- (TencentRequest*)requestWithParams:(NSMutableDictionary *)params
                    andDelegate:(id <TencentRequestDelegate>)delegate;

- (TencentRequest*)requestWithMethodName:(NSString *)methodName
                          andParams:(NSMutableDictionary *)params
                      andHttpMethod:(NSString *)httpMethod
                        andDelegate:(id <TencentRequestDelegate>)delegate;

- (TencentRequest*)requestWithGraphPath:(NSString *)graphPath
                       andDelegate:(id <TencentRequestDelegate>)delegate;

- (TencentRequest*)requestWithGraphPath:(NSString *)graphPath
                         andParams:(NSMutableDictionary *)params
                       andDelegate:(id <TencentRequestDelegate>)delegate;

- (TencentRequest*)requestWithGraphPath:(NSString *)graphPath
                         andParams:(NSMutableDictionary *)params
                     andHttpMethod:(NSString *)httpMethod
                       andDelegate:(id <TencentRequestDelegate>)delegate;

- (QQTLoginViewController*)getLoginViewController:(NSArray *)permissions;

- (BOOL)isSessionValid;

////////////////////////////////////////////////////////////////////////////////
//APIs, can be called after accesstoken and openid have received 

/**
 * Get user info.
 */
- (BOOL)getUserInfo;

/**
 * Get List Album.
 */
- (BOOL)getListAlbum;

/**
 * Add share.
 */
- (BOOL)addShareWithParams:(NSMutableDictionary *)params;

/**
 * Upload picture.
 */
- (BOOL)uploadPicWithParams:(NSMutableDictionary *)params;

/**
 * Add Album.
 */
- (BOOL)addAlbumWithParams:(NSMutableDictionary *)params;

/**
 * Add One Blog.
 */
- (BOOL)addOneBlogWithParams:(NSMutableDictionary *)params;

/**
 * Add topic.
 */
- (BOOL)addTopicWithParams:(NSMutableDictionary *)params;

@end

////////////////////////////////////////////////////////////////////////////////

/**
 * Your application should implement this delegate to receive session callbacks.
 */
@protocol TencentSessionDelegate <NSObject>

@optional

/**
 * Called when the user successfully logged in.
 */
- (void)tencentDidLogin;

/**
 * Called when the user dismissed the dialog without logging in.
 */
- (void)tencentDidNotLogin:(BOOL)cancelled;

/**
 * Called when the user logged out.
 */
- (void)tencentDidLogout;

/**
 * Called when the get_user_info has response.
 */
- (void)getUserInfoResponse:(APIResponse*) response;

/**
 * Called when the get_list_album has response.
 */
- (void)getListAlbumResponse:(APIResponse*) response;

/**
 * Called when the add_share has response.
 */
- (void)addShareResponse:(APIResponse*) response;

/**
 * Called when the add_album has response.
 */
- (void)addAlbumResponse:(APIResponse*) response;

/**
 * Called when the upload_pic has response.
 */
- (void)uploadPicResponse:(APIResponse*) response;

/**
 * Called when the add_one_blog has response.
 */
- (void)addOneBlogResponse:(APIResponse*) response;

/**
 * Called when the add_topic has response.
 */
- (void)addTopicResponse:(APIResponse*) response;


@end